package com.stcc.portal.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * 描述:Swagger2Config
 * 项目名:stcc_gl-parent
 * 包名:com.stcc.portal.config
 * 作者:stcc
 * 创建时间:2021/4/20 14:42
 * 版本:1.0
 */
@Configuration
@EnableSwagger2
//是否开启swagger，正式环境一般是需要关闭的（避免不必要的漏洞暴露！），可根据springboot的多环境配置进行设置
@ConditionalOnProperty(name = "swagger2.enable",  havingValue = "true")
public class Swagger2Config {
    @Bean
    public Docket customDocket() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors
                        .basePackage("com.stcc.portal.controller"))//扫描的包路径
         .build();
     }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
         .title("超叔管理系统")//文档说明
         .version("1.0.0")//文档版本说明
         .contact(new Contact("STCC","www.baidu.com", "ccgogoing1994@outlook.com"))
         .build();
    }
}
